window.onload = function() {
    var regtel = /^1[1|4|5|7|9]\d{9}$/;
    var regqq = /^[1-9][0-9]{4,}$/;
    var regname = /^[\u4e00-\u9fa5]{2,8}$/;
    var regmsg = /^[0-9]{6}$/;
    var regpwd = /^[a-zA-Z0-9_-]{6,16}$/;

    var tel = document.querySelector('#tel');
    var qq = document.querySelector('#qq');
    var name = document.querySelector('#name');
    var msg = document.querySelector('#msg');
    var pwd = document.querySelector('#pwd');
    var surepwd = document.querySelector('#surepwd');

    regexp(tel, regtel);
    regexp(qq, regqq);
    regexp(name, regname);
    regexp(msg, regmsg);
    regexp(pwd, regpwd);


    // 表单验证的函数
    function regexp(ele, reg) {
        ele.onblur = function() {
            if (reg.test(this.value)) {
                this.nextElementSibling.className = 'seccess';
                this.nextElementSibling.innerHTML = '<i class="seccess_icon"></i>恭喜您输入正确';
            }else {
                this.nextElementSibling.className = 'error';
                this.nextElementSibling.innerHTML = '<i class="error_icon"></i>您输入的格式不正确';
            }
        }
    }

    // 两次密码输入是否一致
    surepwd.onblur = function() {
        if (this.value == pwd.value) {
            this.nextElementSibling.className = 'seccess';
            this.nextElementSibling.innerHTML = '<i class="seccess_icon"></i>恭喜您输入正确';
        } else {
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = '<i class="error_icon"></i>两次输入不一致';
        }
    }

}